package mypackage.dao;

import java.util.Vector;

import net.rim.device.api.collection.util.SortedReadableList;
import net.rim.device.api.ui.component.KeywordProvider;
import net.rim.device.api.util.StringUtilities;

public class DataProvider extends SortedReadableList implements KeywordProvider {

	public DataProvider() {
		super(new ListDaoComparator());
	}

	public void deleteList(Object element) {
		doRemove(element);
	}

	public void updateList(Object oldO, Object newO) {
		doUpdate(oldO, newO);
	}

	public void addListWithName(String str) {
		doAdd(new ListDao(str, new Vector()));
	}

	public void addItemInList(int i, String str) {
		((ListDao) getAt(i)).listItems.addElement(str);
	}

	public void deleteItemInList(Object list, Object element) {
		ListDao listDao = (ListDao) list;
		listDao.listItems.removeElement(element);
	}

	public String[] getKeywords(Object element) {
		return StringUtilities.stringToWords(element.toString());
	}

	public Vector getVector() {
		Vector vector = new Vector();
		for (int i = 0; i < size(); i++)
			vector.addElement(getAt(i));
		return vector;
	}

	public void initFromVector(Vector vector) {
		for (int i = 0; i < size(); i++)
			doRemove(getAt(i));
		for (int i = 0; i < vector.size(); i++)
			doAdd(vector.elementAt(i));
	}

}
